﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Foothill.Service.Validation;
using Moq;

namespace Foothill.Service.Test
{
    [TestClass]
    public class ValidationServiceTest
    {
        private IValidationService _underTest;

        private IHtmlSanitizer _htmlSanitizer = new Mock<IHtmlSanitizer>().Object;

        public ValidationServiceTest()
        {
            _underTest = new ValidationService(_htmlSanitizer);
        }

        [TestMethod]
        public void ValidateEmailAddress_ShouldReturnFalse_WhenPassInEmptyString()
        {
            Assert.IsFalse(_underTest.ValidateEmailAddress(string.Empty));
        }

        [TestMethod]
        public void ValidateEmailAddress_ShouldReturnFalse_ForVariousInvalidEmailAddress()
        {
            // an @ character must separate the local and domain parts
            Assert.IsFalse(_underTest.ValidateEmailAddress("abc.example.com"));

            // only one @ is allowed outside quotation marks
            Assert.IsFalse(_underTest.ValidateEmailAddress("A@b@c@example.com"));
            
            Assert.IsFalse(_underTest.ValidateEmailAddress("a\"b(c)d,e:f;g<h>i[j\\k]l@example.com"));
            
            Assert.IsFalse(_underTest.ValidateEmailAddress("just\"not\"right@example.com"));

            Assert.IsFalse(_underTest.ValidateEmailAddress("this is\"not\\allowed@example.com"));

            Assert.IsFalse(_underTest.ValidateEmailAddress("this\\ still\"not\\allowed@example.com"));

            // The following two invalid formats are not handled
            // character dot(.) is last in local part
            //Assert.IsFalse(_underTest.ValidateEmailAddress("Abc.@example.com"));
            // character dot(.) is double
            //Assert.IsFalse(_underTest.ValidateEmailAddress("Abc..123@example.com"));
        }
    }
}
